package com.clkj.xiuzheng.controller.shangcheng;

import com.clkj.xiuzheng.pojo.common.Result;
import com.clkj.xiuzheng.pojo.common.StatusCode;
import com.clkj.xiuzheng.pojo.shangcheng.Address;
import com.clkj.xiuzheng.pojo.shangcheng.Pond;
import com.clkj.xiuzheng.pojo.shangcheng.VipLevel;
import com.clkj.xiuzheng.pojo.shangcheng.VipLevelNum;
import com.clkj.xiuzheng.pojo.shangcheng.dto.VipLevelDto;
import com.clkj.xiuzheng.pojo.shangcheng.vo.VipLevelVo;
import com.clkj.xiuzheng.service.shangcheng.ScVipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/scVip")
@CrossOrigin
@Api(value = "/scVip", tags = {"Z商城vip管理"})
public class ScVipController {

    @Autowired
    private ScVipService scVipService;

    @ApiOperation("根据公司id获取vip集合")
    @PostMapping("/getVipList")
    public Result getVipList(Integer companyId) {
        try {
            List<VipLevelVo> list =  scVipService.getVipList(companyId);
            return new Result(true, StatusCode.OK,"查询成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(" 0根据公司id添加vip等级并添加充值信息 1根据等级直接添加充值信息")
    @PostMapping("/addVipLevel")
    public Result addVipLevel(@RequestBody VipLevelDto vipLevelDto) {
        try {
               scVipService.addVipLevel(vipLevelDto);
            return new Result(true, StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }
    }
    @ApiOperation("根据公司id获取vip等级集合")
    @PostMapping("/getVipLevelList")
    public Result getVipLevelList(@ApiParam(name = "companyId", value = "公司Id")@RequestParam  Integer companyId) {
        try {
            List<VipLevelNum> list =  scVipService.getVipLevelList(companyId);
            return new Result(true, StatusCode.OK,"添加成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }
    }
    @ApiOperation("根据vipId上下架返利活动")
    @PostMapping("/updataStatusByVipId")
    public Result updataStatusByVipId(@ApiParam(name = "vipId", value = "vipId")@RequestParam  Integer vipId,
                                      @ApiParam(name = "type", value = "0下架 1上架")@RequestParam  Integer type) {
        try {
             scVipService.updataStatusByVipId(vipId,type);
            return new Result(true, StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }
    }


    @ApiOperation("小程序根据用户等级获取充值列表或所有")
    @PostMapping("/listVipLevelByUser")
    public Result listVipLevelByUser() {
        try {
            Map map =  scVipService.listVipLevelByUser();
            return new Result(true, StatusCode.OK,"查询成功",map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    @ApiOperation("修改会员等级表数据")
    @PostMapping("/editVipLevelNum")
    public Result editVipLevelNum(VipLevelNum vipLevelNum) {
        try {
             scVipService.editVipLevelNum(vipLevelNum);
             return new Result(true, StatusCode.OK,"修改成功");
        } catch (Exception e) {
             e.printStackTrace();
             return new Result(false, StatusCode.ERROR,"修改失败");
        }
    }

    @ApiOperation("删除会员等级表数据")
    @PostMapping("/deleteVipLevelNum")
    public Result deleteVipLevelNum(Integer levelId) {
        try {
             scVipService.deleteVipLevelNum(levelId);
             return new Result(true, StatusCode.OK,"删除成功");
        } catch (Exception e) {
             e.printStackTrace();
             return new Result(false, StatusCode.ERROR,"删除失败");
        }
    }

    @ApiOperation("修改vip等级表数据")
    @PostMapping("/editVipLevel")
    public Result editVipLevel(VipLevel vipLevel) {
        try {
             scVipService.editVipLevel(vipLevel);
             return new Result(true, StatusCode.OK,"修改成功");
        } catch (Exception e) {
             e.printStackTrace();
             return new Result(false, StatusCode.ERROR,"修改失败");
        }
    }

    @ApiOperation("删除VIP等级表数据")
    @PostMapping("/deleteVipLevel")
    public Result deleteVipLevel(Integer vipId) {
        try {
             scVipService.deleteVipLevel(vipId);
             return new Result(true, StatusCode.OK,"删除成功");
        } catch (Exception e) {
             e.printStackTrace();
             return new Result(false, StatusCode.ERROR,"删除失败");
        }
    }
    @ApiOperation("添加报销额度池信息")
    @PostMapping("/addPond")
    public Result addPond(Pond pond) {
        try {
            scVipService.addPond(pond);
            return new Result(true, StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }
    }

    @ApiOperation("查询报销额度池信息")
    @PostMapping("/listPond")
    public Result listPond() {
        try {
            List<Pond> ponds = scVipService.listPond();
            return new Result(true, StatusCode.OK,"查询成功",ponds);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation("更新报销额度池使启用未启用状态")
    @PostMapping("/updatePond")
    public Result updatePond(Integer pondId,Integer status) {
        try {
            scVipService.updatePond(pondId,status);
            return new Result(true, StatusCode.OK,"查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }



}
